from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-11 14:02:43.465930
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 11, Sep, 2022
Time: 14:02:52
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3931
Nobs: 776.000 HQIC: -50.7252
Log likelihood: 9942.08 FPE: 7.58846e-23
AIC: -50.9328 Det(Omega_mle): 6.76249e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298519 0.054267 5.501 0.000
L1.Burgenland 0.107477 0.036124 2.975 0.003
L1.Kärnten -0.106676 0.019201 -5.556 0.000
L1.Niederösterreich 0.205917 0.075604 2.724 0.006
L1.Oberösterreich 0.113825 0.073133 1.556 0.120
L1.Salzburg 0.253341 0.038664 6.552 0.000
L1.Steiermark 0.036307 0.050408 0.720 0.471
L1.Tirol 0.106422 0.040843 2.606 0.009
L1.Vorarlberg -0.060586 0.035137 -1.724 0.085
L1.Wien 0.050009 0.065036 0.769 0.442
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058675 0.112643 0.521 0.602
L1.Burgenland -0.033537 0.074984 -0.447 0.655
L1.Kärnten 0.047532 0.039857 1.193 0.233
L1.Niederösterreich -0.177062 0.156934 -1.128 0.259
L1.Oberösterreich 0.396567 0.151804 2.612 0.009
L1.Salzburg 0.289294 0.080256 3.605 0.000
L1.Steiermark 0.106228 0.104635 1.015 0.310
L1.Tirol 0.313673 0.084779 3.700 0.000
L1.Vorarlberg 0.027377 0.072934 0.375 0.707
L1.Wien -0.021659 0.134997 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191627 0.027861 6.878 0.000
L1.Burgenland 0.089556 0.018546 4.829 0.000
L1.Kärnten -0.008490 0.009858 -0.861 0.389
L1.Niederösterreich 0.260786 0.038815 6.719 0.000
L1.Oberösterreich 0.134024 0.037547 3.570 0.000
L1.Salzburg 0.045984 0.019850 2.317 0.021
L1.Steiermark 0.018150 0.025880 0.701 0.483
L1.Tirol 0.093015 0.020969 4.436 0.000
L1.Vorarlberg 0.058353 0.018039 3.235 0.001
L1.Wien 0.118087 0.033390 3.537 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108575 0.028363 3.828 0.000
L1.Burgenland 0.046873 0.018881 2.483 0.013
L1.Kärnten -0.015053 0.010036 -1.500 0.134
L1.Niederösterreich 0.191398 0.039515 4.844 0.000
L1.Oberösterreich 0.290119 0.038224 7.590 0.000
L1.Salzburg 0.112095 0.020208 5.547 0.000
L1.Steiermark 0.102371 0.026347 3.886 0.000
L1.Tirol 0.111181 0.021347 5.208 0.000
L1.Vorarlberg 0.069631 0.018365 3.792 0.000
L1.Wien -0.017853 0.033992 -0.525 0.599
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131006 0.051486 2.544 0.011
L1.Burgenland -0.050686 0.034273 -1.479 0.139
L1.Kärnten -0.040199 0.018218 -2.207 0.027
L1.Niederösterreich 0.170533 0.071731 2.377 0.017
L1.Oberösterreich 0.138872 0.069386 2.001 0.045
L1.Salzburg 0.287218 0.036683 7.830 0.000
L1.Steiermark 0.034563 0.047826 0.723 0.470
L1.Tirol 0.161276 0.038750 4.162 0.000
L1.Vorarlberg 0.100794 0.033336 3.024 0.002
L1.Wien 0.068473 0.061704 1.110 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056328 0.040980 1.375 0.169
L1.Burgenland 0.040198 0.027279 1.474 0.141
L1.Kärnten 0.050663 0.014500 3.494 0.000
L1.Niederösterreich 0.220909 0.057093 3.869 0.000
L1.Oberösterreich 0.283137 0.055227 5.127 0.000
L1.Salzburg 0.045689 0.029198 1.565 0.118
L1.Steiermark -0.001138 0.038066 -0.030 0.976
L1.Tirol 0.147734 0.030843 4.790 0.000
L1.Vorarlberg 0.072993 0.026534 2.751 0.006
L1.Wien 0.084298 0.049112 1.716 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180542 0.049065 3.680 0.000
L1.Burgenland -0.006478 0.032661 -0.198 0.843
L1.Kärnten -0.061318 0.017361 -3.532 0.000
L1.Niederösterreich -0.084165 0.068357 -1.231 0.218
L1.Oberösterreich 0.196493 0.066123 2.972 0.003
L1.Salzburg 0.056352 0.034958 1.612 0.107
L1.Steiermark 0.231571 0.045577 5.081 0.000
L1.Tirol 0.493582 0.036928 13.366 0.000
L1.Vorarlberg 0.048138 0.031769 1.515 0.130
L1.Wien -0.052507 0.058802 -0.893 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166388 0.056309 2.955 0.003
L1.Burgenland -0.010220 0.037484 -0.273 0.785
L1.Kärnten 0.067063 0.019924 3.366 0.001
L1.Niederösterreich 0.206000 0.078450 2.626 0.009
L1.Oberösterreich -0.070674 0.075886 -0.931 0.352
L1.Salzburg 0.211572 0.040119 5.274 0.000
L1.Steiermark 0.115539 0.052306 2.209 0.027
L1.Tirol 0.071903 0.042380 1.697 0.090
L1.Vorarlberg 0.121665 0.036459 3.337 0.001
L1.Wien 0.122349 0.067484 1.813 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357782 0.032578 10.982 0.000
L1.Burgenland 0.005459 0.021687 0.252 0.801
L1.Kärnten -0.023354 0.011527 -2.026 0.043
L1.Niederösterreich 0.214684 0.045388 4.730 0.000
L1.Oberösterreich 0.188371 0.043904 4.290 0.000
L1.Salzburg 0.046217 0.023212 1.991 0.046
L1.Steiermark -0.015706 0.030262 -0.519 0.604
L1.Tirol 0.106347 0.024520 4.337 0.000
L1.Vorarlberg 0.073606 0.021094 3.489 0.000
L1.Wien 0.047949 0.039044 1.228 0.219
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040224 0.148515 0.192007 0.157146 0.124189 0.112777 0.066172 0.222575
Kärnten 0.040224 1.000000 -0.003942 0.132017 0.041716 0.095645 0.430484 -0.052295 0.100262
Niederösterreich 0.148515 -0.003942 1.000000 0.337299 0.151681 0.298314 0.108173 0.183498 0.323584
Oberösterreich 0.192007 0.132017 0.337299 1.000000 0.227638 0.330344 0.172431 0.167903 0.264714
Salzburg 0.157146 0.041716 0.151681 0.227638 1.000000 0.147035 0.122881 0.147417 0.133853
Steiermark 0.124189 0.095645 0.298314 0.330344 0.147035 1.000000 0.151554 0.138435 0.079217
Tirol 0.112777 0.430484 0.108173 0.172431 0.122881 0.151554 1.000000 0.115101 0.153557
Vorarlberg 0.066172 -0.052295 0.183498 0.167903 0.147417 0.138435 0.115101 1.000000 0.007017
Wien 0.222575 0.100262 0.323584 0.264714 0.133853 0.079217 0.153557 0.007017 1.000000